<!DOCTYPE html>
<html>

<head lang="en">
    <title>找攻略</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/myStrategyComment.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/plugins/form/jquery.form.js"></script>
    <script src="/js/common.js"></script>
    <script>
        $(function () {
            //选择星星,获取全部的星星绑定点击事件
            //通过this获取单个值
            //循环所有的星星,移除空星,再添加实心
            //用户取消时,移除实心,添加空星
            var num;
            $('.star i').click(function (data) {
                num = $(this).data("num");
                var all = $('.star i');
                all.removeClass('fa-star').addClass('fa-star-o');
                for (var i = 0; i < num; i++) {
                    $(all[i]).removeClass('fa-star-o').addClass('fa-star')
                }
            });
            //提供一个form表单隐藏域, enctype="multipart/form-data"
            // 上传图片:绑定上传按钮和文件框
            //文件框绑定change事件
            //判断是否有值
            //表单发送ajax请求
            //状态正常, 则给图片设置路径
            var rect;
            $('.rect').click(function () {
                rect = $(this);
                $('#file').click();
            });
            $('#file').change(function () {
                if ($(this).val()) {
                    $('#imageForm').ajaxSubmit(function (data) {
                        if (data.status == 1) {
                            rect.html('<img src="' + data.url + '"/>');
                        }
                    })
                }
            });

            var params = getParams();
            console.log(params);
            if(params.strategyId){
                //获取前6个的标签    <input type="checkbox" autocomplete="off" render-value="'+value+'">value
                $.get('/strategies/' + params.strategyId + '/tags',function (data) {
                    var json = {
                        arr: data.list
                    };
                    $('.tagInfo').renderValues(json,{
                        getTags:function (item,value) {
                            $(item).html(' <input type="checkbox" autocomplete="off" render-value="'+value+'">'+value)
                        }
                    })
                });

            }

            //提交评价按钮
            //获取所有的图片
            $('#submitBtn').click(function () {
                if (params.strategyId) {
                    //获取选中的标签
                    var tags = [];
                    var inputs = $('label.active');  // ???
                    var i = 0;
                    for (; i < inputs.length; i++) {
                        tags[i] = $(inputs[i]).children().val();
                    }
                    //获取自定义标签
                    var myTags = $('#myTags').val();
                    var arr = myTags.split(" ");
                    for (var j = 0; j < arr.length; j++) {
                        var tag = arr[j];
                        if (tag != "") {
                            tags[i++] = tag;
                        }
                    }
                    //去掉[]
                    jQuery.ajaxSettings.traditional = true;
                    //所有图片
                    var imgs = $('.imgs img');
                    var temp = "";
                    for (var i = 0; i < imgs.length; i++) {
                        temp += $(imgs[i]).attr('src') + ";";
                    }
                    //
                    var data = {
                        starNum: num,
                        content: $('[name="content"]').val(),
                        imgUrls: temp,
                        tags:tags
                    };
                    $.post('/strategies/' + params.strategyId + '/comments', data, function (data) {
                        window.location.href = "/strategyCatalogs.html?id=" + params.strategyId;
                    })

                }
            })

        })
    </script>
</head>

<body>

<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="javascript:window.history.go(-1)">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>

        </div>
        <div class="col">
            <span>点评</span>
        </div>
        <div class="col"></div>
    </div>
</div>

<div class="comment">
    <form id="imageForm" style="display: none" action="/images" enctype="multipart/form-data"
          method="post">
        <input id="file" type="file" name="file">
    </form>
    <div class="container star">
        <p>你对该旅游地的评价</p>
        <i class="fa fa-star-o fa-lg" data-num="1"></i>
        <i class="fa fa-star-o fa-lg" data-num="2"></i>
        <i class="fa fa-star-o fa-lg" data-num="3"></i>
        <i class="fa fa-star-o fa-lg" data-num="4"></i>
        <i class="fa fa-star-o fa-lg" data-num="5"></i>
    </div>
    <hr/>
    <div class="container tag tagInfo" >
        <p>请为该旅游地选择合适的标签（大家都在评）</p>
        <div class="btn-group-toggle" data-toggle="buttons" render-loop="arr" >
            <label class="btn btn-outline-danger" render-key="arr.name" render-fun="getTags">

            </label>

        </div>

        <p>添加你自己的标签</p>
        <input id="myTags" name="myTags" class="form-control" placeholder="请使用空格隔开标签，每个标签不超8个字"/>

        <p>更多评价内容</p>
        <textarea name="content" class="form-control" rows="5" placeholder="请填写你对该旅游地的评价"></textarea>
    </div>
    <div class="container imgs ">
        <p>上传图片</p>

        <div class="row">
            <div class="col-3 rect">
                <span>上传</span>
            </div>
            <div class="col-3 rect">
                <span>上传</span>
            </div>
            <div class="col-3 rect">
                <span>上传</span>
            </div>
            <div class="col-3 rect">
                <span>上传</span>
            </div>
            <div class="col-3 rect">
                <span>上传</span>
            </div>
            <div class="col-3 rect">
                <span>上传</span>
            </div>
        </div>
    </div>

</div>


<div class="operation">
    <button class="btn" onclick="window.history.go(-1)">放弃评价</button>
    <button class="btn" id="submitBtn">提交评价</button>
</div>


</body>


</html>